package com.itboye.textileexpres.top;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.textileexpes.beans.Category_TypeTwo;
import com.itboye.textileexpres.R;

public class GoodsExpandlistAdapter extends BaseAdapter {
	Context context;
	List<Category_TypeTwo> list = new ArrayList<Category_TypeTwo>();
	int type;
	OnClickListener totopclicker;

	public GoodsExpandlistAdapter(Context context, List<Category_TypeTwo> list,
			int type, OnClickListener totopclicker) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.list = list;
		this.type = type;
		this.totopclicker = totopclicker;
	}

	public GoodsExpandlistAdapter(Context context, int type) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.type = type;
	}

	public GoodsExpandlistAdapter(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	// @Override
	// public int getItemViewType(int position) {
	// // TODO Auto-generated method stub
	// return type;
	// }

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = (LinearLayout) inflater.inflate(
					R.layout.item_goodsfragmenta_dapter, null);
			holder.type_tv = (TextView) convertView.findViewById(R.id.type_tv);
			holder.to_top = (ImageView) convertView.findViewById(R.id.to_top);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.type_tv.setText(list.get(position).getName());
		holder.to_top.setOnClickListener(totopclicker);
		holder.to_top.setTag(position);
		return convertView;
	}

	class ViewHolder {
		TextView type_tv;
		ImageView to_top;
	}
}
